package config

import (
	"fmt"
	"gopkg.in/ini.v1"
)

var (
	AppMode   string
	HttpPort  string
	JwtSecret string

	// MySQL 数据库信息
	DBHost        string
	DBPort        string
	DBUser        string
	DBPassWord    string
	DBName        string
	DBMaxIdle     int
	DBMaxOpen     int
	DBMaxLifetime int
)

func init() {
	file, err := ini.Load(".env")
	if err != nil {
		fmt.Println("读取配置文件发生错误 ", err)
	}
	AppMode = file.Section("server").Key("APP_MODE").String()
	HttpPort = file.Section("server").Key("APP_PORT").String()
	JwtSecret = file.Section("server").Key("JWT_SECRET").String()

	DBHost = file.Section("database").Key("DB_HOST").String()
	DBPort = file.Section("database").Key("DB_PORT").String()
	DBUser = file.Section("database").Key("DB_USERNAME").String()
	DBPassWord = file.Section("database").Key("DB_PASSWORD").String()
	DBName = file.Section("database").Key("DB_DATABASE").String()
	DBMaxOpen = file.Section("database").Key("DB_MAX_OPEN_CONNECTIONS").MustInt(100)
	DBMaxIdle = file.Section("database").Key("DB_MAX_IDLE_CONNECTIONS").MustInt(25)
	DBMaxLifetime = file.Section("database").Key("DB_MAX_LIFE_SECONDS").MustInt(300)
}
